package eu.jpereira.trainings.designpatterns.creational.builder.json;

import eu.jpereira.trainings.designpatterns.creational.builder.ReportBodyBuilder;
import eu.jpereira.trainings.designpatterns.creational.builder.model.ReportBody;

public class JSONReportBodyBuilder implements ReportBodyBuilder{
    JSONReportBody reportBody = new JSONReportBody();
    
	@Override
	public void setCustomerName(String customerName) {
		reportBody.addContent("sale:{customer:{");
		reportBody.addContent("name:\"");
		reportBody.addContent(customerName);
	}

	@Override
	public void setCustomerPhone(String phoneNumber) {
		reportBody.addContent("\",phone:\"");
		reportBody.addContent(phoneNumber);
		reportBody.addContent("\"}");
	}

	@Override
	public void itemsListStart() {
		reportBody.addContent(",items:[");
	}
	
	@Override
	public void itemsListEnd() {
		reportBody.addContent("]}");
	}

	@Override
	public void newItem(String name, int quantity, double price, boolean hasNext) {
		reportBody.addContent("{name:\"");
		reportBody.addContent(name);
		reportBody.addContent("\",quantity:");
		reportBody.addContent(String.valueOf(quantity));
		reportBody.addContent(",price:");
		reportBody.addContent(String.valueOf(price));
		reportBody.addContent("}");
		
		if(hasNext) {
			reportBody.addContent(",");
		}
	}

	@Override
	public ReportBody getReportBody() {
		return reportBody;
	}

}
